home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / utilit~1 / futilsrc.zoo / fileutil / lib / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-30  |  2.5 KB  |  103 lines

  1. /* error.c -- error handler for noninteractive utilities
  2.    Copyright (C) 1990-1991 Free Software Foundation, Inc.
  3.  
  4.    This program is free software; you can redistribute it and/or modify
  5.    it under the terms of the GNU General Public License as published by
  6.    the Free Software Foundation; either version 2, or (at your option)
  7.    any later version.
  8.  
  9.    This program is distributed in the hope that it will be useful,
  10.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.    GNU General Public License for more details.
  13.  
  14.    You should have received a copy of the GNU General Public License
  15.    along with this program; if not, write to the Free Software
  16.    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  17.  
  18. /* David MacKenzie */
  19.  
  20. #include <stdio.h>
  21.  
  22. #ifndef VPRINTF_MISSING
  23.  
  24. #ifdef __STDC__
  25. #include <stdarg.h>
  26. #define VA_START(args, lastarg) va_start(args, lastarg)
  27. #else
  28. #include <varargs.h>
  29. #define VA_START(args, lastarg) va_start(args)
  30. #endif
  31.  
  32. #else
  33.  
  34. #ifndef DOPRNT_MISSING
  35. #define va_alist args
  36. #define va_dcl int args;
  37. #else
  38. #define va_alist a1, a2, a3, a4, a5, a6, a7, a8
  39. #define va_dcl char *a1, *a2, *a3, *a4, *a5, *a6, *a7, *a8;
  40. #endif
  41.  
  42. #endif
  43.  
  44. #ifdef STDC_HEADERS
  45. #include <stdlib.h>
  46. #include <string.h>
  47. #else
  48. void exit ();
  49.  
  50. static char *
  51. strerror (errnum)
  52.      int errnum;
  53. {
  54.   extern char *sys_errlist[];
  55.   extern int sys_nerr;
  56.  
  57.   if (errnum > 0 && errnum < sys_nerr)
  58.     return sys_errlist[errnum];
  59.   return "Unknown system error";
  60. }
  61. #endif
  62.  
  63. /* Print the program name and error message MESSAGE, which is a printf-style
  64.    format string with optional args.
  65.    If ERRNUM is nonzero, print its corresponding system error message.
  66.    Exit with status STATUS if it is nonzero. */
  67. /* VARARGS */
  68. void
  69. #if !defined (VPRINTF_MISSING) && defined (__STDC__)
  70. error (int status, int errnum, char *message, ...)
  71. #else
  72. error (status, errnum, message, va_alist)
  73.      int status;
  74.      int errnum;
  75.      char *message;
  76.      va_dcl
  77. #endif
  78. {
  79.   extern char *program_name;
  80. #ifndef VPRINTF_MISSING
  81.   va_list args;
  82. #endif
  83.  
  84.   fprintf (stderr, "%s: ", program_name);
  85. #ifndef VPRINTF_MISSING
  86.   VA_START (args, message);
  87.   vfprintf (stderr, message, args);
  88.   va_end (args);
  89. #else
  90. #ifndef DOPRNT_MISSING
  91.   _doprnt (message, &args, stderr);
  92. #else
  93.   fprintf (stderr, message, a1, a2, a3, a4, a5, a6, a7, a8);
  94. #endif
  95. #endif
  96.   if (errnum)
  97.     fprintf (stderr, ": %s", strerror (errnum));
  98.   putc ('\n', stderr);
  99.   fflush (stderr);
  100.   if (status)
  101.     exit (status);
  102. }
  103.